package cn.changeforyou.devUtils.copy;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.io.File;

/**
 * 回退文档清单
 * 回退的步骤是
 * 1. 把清单内的文件全部移动到回收站
 * 2. 把copy内的全部文件复制到目标区
 *
 * @version 1.0
 * @description
 * @auther zhyu
 * 2022-9-24 19:28
 */
@Data
public class RecoveryFileInfo implements Comparable<RecoveryFileInfo> {

    /**
     * 源文件
     */
    private File srcFile;
    /**
     * 是否需要备份
     */
    private boolean needBackup;
    /**
     * 备份文件
     */
    private File backFile;
    /**
     * 目标文件
     */
    private File targetFile;
    /**
     * 备份成功
     */
    private Boolean backSuccess;
    /**
     * 复制成功
     */
    private boolean copySuccess;

    /**
     * 备份文件路径
     */
    private String backFilePath;
    /**
     * 目标文件路径
     */
    private String targetFilePath;
    /**
     * 源目标文件路径
     */
    private String srcFilePath;

    private boolean backFileFind;
    private boolean srcFileFind;
    private boolean targetFileFind;
    private boolean needOverride;
    private boolean needDelete;
    private boolean overrideSuccess;
    private boolean deleteSuccess;

    private String errorMessage;

    /**
     * 获取替换路径
     */
    public String getOverridePath(){
        if(needOverride){
            return backFilePath;
        }else {
            return null;
        }
    }
    @Override
    public int compareTo(RecoveryFileInfo o) {
        if(o == null){
            return 1;
        }
        if(this.targetFileFind && !o.targetFileFind){
            return 1;
        }else if(!this.targetFileFind && o.targetFileFind){
            return -1;
        }else if(!this.targetFileFind && !o.targetFileFind){
            return 0;
        }
        boolean thisNotError = StrUtil.isBlank(this.errorMessage);
        boolean thatNotError = StrUtil.isBlank(o.errorMessage);
        if(thisNotError && !thatNotError){
            return 1;
        }else if(!thisNotError && thatNotError){
            return -1;
        }
        if(this.needOverride && !o.needOverride){
            return 1;
        }else if(!this.needOverride && o.needOverride){
            return -1;
        }
        return this.getTargetFilePath().compareTo(o.getTargetFilePath());
    }
}
